<?php
/**
 * Author: Traveler
 * Time  : 2021/12/25 0025 15:56
 */

namespace app\validate;

use app\ErrorCode;
use think\Validate;

class RoleValidate extends Validate
{
    /**
     * 验证规则
     *
     * @var string[]
     */
    protected $rule = [
        'name'    => 'require|max:16|unique:\\app\\model\\RoleModel',
        'status'  => 'require|in:0,1',
        'menuIds' => 'require'
    ];

    /**
     * 提示信息
     *
     * @var string[]
     */
    protected $message = [
        'name.require'    => ErrorCode::REQUIRE_ROLE_NAME,
        'name.max'        => ErrorCode::INVALID_ROLE_NAME_LEN,
        'name.unique'     => ErrorCode::DUPLICATE_ROLE_NAME,
        'status.require'  => ErrorCode::REQUIRE_ROLE_STATUS,
        'status.in'       => ErrorCode::INVALID_ROLE_STATUS,
        'menuIds.require' => ErrorCode::REQUIRE_PERMISSION_LIST,
    ];

    /**
     * 验证场景：基础信息
     *
     * @return RoleValidate
     */
    public function sceneBase(): RoleValidate
    {
        return $this->only(['name', 'status']);
    }

    /**
     * 验证场景：分配权限
     *
     * @return RoleValidate
     */
    public function sceneAssign(): RoleValidate
    {
        return $this->only(['menuIds']);
    }
}